function findParent(tree:any[], parentId:any, child:any){
    
    for(let t of tree){
        if(t.id == parentId){
            if(!t.children){
                t.children = []
            }
            t.children.push(child)
        }

        if(t.children){
            findParent(t.children, parentId, child)
        }

        
    }
}

export default function(list :any[]) {

    let tree = []
    for(let item of list){
        if(item.parentId == null){
            tree.push(item)
        }
    }
    for(let item of list){
        if(item.parentId){
            findParent(tree, item.parentId, item)
        }
    }

    return tree
}